<?php

// Error if we don't have a Project ID and Crudset ID
//Incluce DB connect 
include_once "quickcrud_connect.php";
//include_once "commonctls.php";
include_once "CF_mysql_com.php";
//include_once "CF_all_com.php";

include_once "qc_functions.php";

if (!isset($_REQUEST['project_id']) OR $_REQUEST['project_id'] == 0 ){

        $result = "First select Project and CRUDset";
        $result = urlencode($result);

        $header_text = "Location: leftmenu.php?project_id=$project_id&crudset_id=$crudset_id&result=$result";
        header($header_text); /* Redirect browser */
        exit;
}

if (!isset($_REQUEST['table_id']) ){
    $project_id = $_REQUEST['project_id'];

    $current_db = lookup_value('project_db', 'projects', "project_id = $project_id");
    $ar_tables = get_array_query("SELECT tablesource_id, table_name FROM tablesources WHERE project_id = $project_id ");
    $prevalue[1]['tablesource_id'] = 0;
    $prevalue[1]['table_name'] = 'Please Select';
    $dd_tables =  make_array_dd($ar_tables, 'table_id',  'table_name','tablesource_id', 0, 40, '', $prevalue);

    $txt_select_table = "<form name='select_table' action='all_table_to_set.php' method='get'>\n";
    $txt_select_table .= "<p>Select Table Name</p>\n <p>$dd_tables</p>\n";
    $txt_select_table .= "<input type='hidden' name='project_id' value='$project_id' ><input type='submit' value='go'>\n";
    echo $txt_select_table;

	exit;

}
$project_id = $_REQUEST['project_id'];
$table_id = $_REQUEST['table_id'];
$crudset_id = $_REQUEST['crudset_id'];

fill_set_from_table($table_id, $project_id, $crudset_id, 'inline_edit');

$table_name = lookup_value('table_name', 'tablesources', "tablesource_id = $table_id");
$result = "Table: $table_name Variables added to Set";
$result = urlencode($result);
$header_text = "Location: leftmenu.php?project_id=$project_id&crudset_id=$crudset_id&result=$result";
header($header_text); /* Redirect browser */
exit;



?>